package com.webex.ta.hydra.gui.component;

import javax.swing.*;
import java.awt.*;
import java.util.Set;
import java.util.HashSet;

/**
 * Created by Cisco WebEx.
 * User: vegaz
 * Date: 2010-9-19
 * Time: 9:29:54
 */
public class ClosableTabbedPane extends JTabbedPane {
    private Set<CloseEventListener> listeners = new HashSet<CloseEventListener>();

    public ClosableTabbedPane(int tabPlacement, int tabLayoutPolicy) {
        super(tabPlacement, tabLayoutPolicy);
        this.setUI(new ClosableTabbedPaneUI());
    }

    public ClosableTabbedPane() {
        super();
        this.setUI(new ClosableTabbedPaneUI());
    }

    public ClosableTabbedPane(int tabPlacement) {
        super(tabPlacement);
        this.setUI(new ClosableTabbedPaneUI());
    }

    public void addCloseEventListener(CloseEventListener listener) {
        listeners.add(listener);
    }

    protected void fireClosingEvent(int tabIndex) {
        for (CloseEventListener listener : listeners) {
            listener.onClosing(new CloseEvent(this, tabIndex));
        }
    }

    @Override
    public void addTab(String title, Component component) {
        super.addTab(title, component);
    }

    public void addClosableTab() {

    }

    @Override
    public void addTab(String title, Icon icon, Component component) {
        super.addTab(title, icon, component);
    }

    @Override
    public void addTab(String title, Icon icon, Component component, String tip) {
        super.addTab(title, icon, component, tip);
    }


}
